package com.exercise.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exercise.common.R;
import com.exercise.entity.OrderDetail;
import com.exercise.entity.Orders;
import com.exercise.service.OrderDetailService;
import com.exercise.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈凯
 * @create 2023-03-09-14:43
 */
@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private OrderDetailService orderDetailService;

    /**
     * 提交订单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submitOrder(@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("订单提交成功");
    }

    /**
     * 查看订单
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page> getOrder(int page, int pageSize){
        Page<OrderDetail> orderDetailPage = new Page<>(page, pageSize);
        orderDetailService.page(orderDetailPage);
        return R.success(orderDetailPage);
    }
}
